﻿#define _CRT_SECURE_NO_WARNINGS 1
//栈：删除字符串中的所有相邻重复项（easy)：https://leetcode.cn/problems/remove-all-adjacent-duplicates-in-string/description/
class Solution
{
public:
	string removeDuplicates(string s)
	{
		string ret; // 搞⼀个数组，模拟栈结构即可
		for (auto ch : s)
		{
			if (ret.size() && ch == ret.back()) ret.pop_back(); // 出栈
			else ret += ch; // ⼊栈
		}
		return ret;
	}
};
//⽐较含退格的字符串（easy）:https://leetcode.cn/problems/backspace-string-compare/description/
class Solution
{
public:
	bool backspaceCompare(string s, string t)
	{
		return changeStr(s) == changeStr(t);
	}
	string changeStr(string& s)
	{
		string ret; // ⽤数组模拟栈结构
		for (char ch : s)
		{
			if (ch != '#') ret += ch;
			else
			{
				if (ret.size()) ret.pop_back();
			}
		}
		return ret;
	}
};
